package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.wx.goods.bo.PageInfoWxBO;
import com.cskaoyan.bean.wx.goods.vo.*;
import com.cskaoyan.service.wx.WxGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname GoodsController
 * @Description
 * @Date 2021/8/14 14:01
 * @Author : xujun
 */
@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {

    @Autowired
    WxGoodsService wxGoodsService;


    /**
     * 商品总数
     *
     * @return
     */
    @RequestMapping("count")
    public BaseRespVo count() {

        CountVo vo = wxGoodsService.count();

        return BaseRespVo.ok(vo);
    }


    /**
     * 商品类目
     *
     * @param id
     * @return
     */
    @RequestMapping("category")
    public BaseRespVo category(Integer id) {

        CategoryVo vo = wxGoodsService.category(id);

        return BaseRespVo.ok(vo);
    }


    /**
     * 商品列表
     * @param bo
     * @param keyword
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(PageInfoWxBO bo, String keyword) {

        ListVo vo ;

        if (keyword == null) {
            vo = wxGoodsService.getGoodsList(bo);
        }else {
            vo = wxGoodsService.searchGoodsList(bo, keyword);
        }

        return BaseRespVo.ok(vo);
    }


    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {

        GoodsDetailVo vo = wxGoodsService.detail(id);

        return BaseRespVo.ok(vo);
    }


    /**
     * 显示相似的商品，最多显示6个
     *
     * @param id
     * @return
     */
    @RequestMapping("related")
    public BaseRespVo related(Integer id) {

        GoodsRelatedVo vo = wxGoodsService.related(id);

        return BaseRespVo.ok(vo);
    }
}
